import datetime

from fastapi import APIRouter
from fastapi_amis_admin.globals.deps import AsyncSess
from fastapi_user_auth.globals.deps import CurrentUser

from apps.tower.models import TowerV1

# 通过注册依赖方式验证用户权限,当前路由注册器下全部路由都将进行权限验证.
router = APIRouter(prefix="/tower", tags=["TowerAPI"])


@router.get("/update/{id}", response_model=TowerV1, summary="更新文章")
async def update_article(id: int, session: AsyncSess, user: CurrentUser):
    tower = await session.get(TowerV1, id)
    if tower:
        # tower.user_id = user.id
        # tower.create_time = datetime.datetime.now()
        await session.flush()
    return tower
